package com.cf.r1020;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class a {

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        int T = Integer.parseInt(br.readLine());
        while (T-- > 0) {
            solve();
        }
        out.flush();
        out.close();
        br.close();
    }

    static void solve() throws IOException {
        int n = Integer.parseInt(br.readLine());
        char[] s = br.readLine().toCharArray();
        int count = 0;
        for (int i = 0; i < n; i++) {
            if (s[i] == '1') {
                count++;
            }
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (s[i] == '0') {
                ans += count + 1;
            } else {
                ans += count - 1;
            }
        }
        out.println(ans);
    }
}
